import java.util.*;

public class TestWork {
    //考试题
    public static void mian(String[] args) {
        //输入信息
        Scanner input = new Scanner(System.in);
        //多组输入
        while(input.hasNextInt()) {
            int num = input.nextInt();
            int ret = func(num);
            System.out.println(num);
        }
    }

    public static int func(int num) {
        int f1 = 0;
        int f2 = 0;
        int f3 = 0;
        while(f3 < num) {
            f3 = f1 + f2;
            if (f3 >= num) {
                break;
            }
            f1 = f2;
            f2 = f3;
        }
        if (Math.abs(f2 - num) > Math.abs(f3 - num)) {
            return Math.abs(f3 - num);
        }else {
            return Math.abs(f2 - num);
        }
    }
}
